class FormalContext:
    def __init__(self, num_objects, num_attributes):
        self.num_objects = num_objects
        self.num_attributes = num_attributes
        self.context = []  # 二进制矩阵，表示对象与属性的关系

    def add_object(self, object_row):
        self.context.append(object_row)

    def get_object(self, index):
        return self.context[index]

    def __str__(self):
        return '\n'.join([', '.join(map(str, row)) for row in self.context])


def read_formal_context(filename):
    with open(filename, 'r') as file:
        # 读取第一行，获取对象数和属性数
        num_objects, num_attributes = map(int, file.readline().strip().split(','))

        # 初始化 FormalContext
        context = FormalContext(num_objects, num_attributes)

        # 读取后续行，并添加到 context 中
        for line in file:
            object_row = list(map(int, line.strip().split(',')))
            context.add_object(object_row)

        return context
